package windows;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.JLabel;

import controllers.DataInsertion;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Scenarios extends javax.swing.JFrame {


	public WindowManager windowManager;
	private JTextField txt_X1;
	private JTextField txt_Y1;
	private JTextField txt_X2;
	private JTextField txt_Y2;
	private JTextField txt_X3;
	private JTextField txt_Y3;
	private JTextField txt_X4;
	private JTextField txt_Y4;
	private JTextField txt_X5;
	private JTextField txt_Y5;
	private JTextField txt_ScenarioName;
	private JLabel lblNaam;
	
	public Scenarios(WindowManager windowManager2) {
		this.windowManager = windowManager2;
		setMinimumSize(new Dimension(400, 400));
		setPreferredSize(new Dimension(400, 400));
		getContentPane().setLayout(null);
		
		JButton btnScenarioOpslaan = new JButton("Scenario Opslaan");
		btnScenarioOpslaan.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {	
				String scenName = txt_ScenarioName.getText().toLowerCase();
				String wpX1 = txt_X1.getText();
				String wpY1 = txt_Y1.getText();
				String wpX2 = txt_X2.getText();
				String wpY2 = txt_Y2.getText();
				String wpX3 = txt_X3.getText();
				String wpY3 = txt_Y3.getText();
				String wpX4 = txt_X4.getText();
				String wpY4 = txt_Y4.getText();
				String wpX5 = txt_X5.getText();
				String wpY5 = txt_Y5.getText();
		        try {
		            String filename= "C://logs//" + scenName + ".txt"; 
		            
		            String LOG = wpX1 + "\n" + wpY1 + "\n" + wpX2 + "\n" + wpY2
		            		+ "\n" +wpX3 + "\n" + wpY3 + "\n" + wpX4 + "\n" + wpY4 + "\n" +wpX5 + "\n" + wpY5;
		            boolean append = true; 
		            
		            File LOGDir = new File("C://logs//");        
		            if (!LOGDir.exists())
		                {
		                 LOGDir.mkdir();
		                }
		 
		            FileWriter fw = new FileWriter(filename,append); 
		            fw.write(LOG);//appends the string to the file 
		            fw.close();  
		        }
		        catch (IOException e)
		        {
		            System.out.println("Exception " + e);       
		        }
		        windowManager.showWindow(windowManager.mainMenu);
			}
		});
		btnScenarioOpslaan.setBounds(74, 262, 157, 23);
		getContentPane().add(btnScenarioOpslaan);
		
		txt_X1 = new JTextField();
		txt_X1.setBounds(34, 57, 86, 20);
		getContentPane().add(txt_X1);
		txt_X1.setColumns(10);
		
		txt_Y1 = new JTextField();
		txt_Y1.setBounds(145, 57, 86, 20);
		getContentPane().add(txt_Y1);
		txt_Y1.setColumns(10);
		
		txt_X2 = new JTextField();
		txt_X2.setBounds(34, 88, 86, 20);
		getContentPane().add(txt_X2);
		txt_X2.setColumns(10);
		
		txt_Y2 = new JTextField();
		txt_Y2.setBounds(145, 88, 86, 20);
		getContentPane().add(txt_Y2);
		txt_Y2.setColumns(10);
		
		txt_X3 = new JTextField();
		txt_X3.setBounds(34, 119, 86, 20);
		getContentPane().add(txt_X3);
		txt_X3.setColumns(10);
		
		txt_Y3 = new JTextField();
		txt_Y3.setBounds(145, 119, 86, 20);
		getContentPane().add(txt_Y3);
		txt_Y3.setColumns(10);
		
		txt_X4 = new JTextField();
		txt_X4.setBounds(34, 150, 86, 20);
		getContentPane().add(txt_X4);
		txt_X4.setColumns(10);
		
		txt_Y4 = new JTextField();
		txt_Y4.setBounds(145, 150, 86, 20);
		getContentPane().add(txt_Y4);
		txt_Y4.setColumns(10);
		
		txt_X5 = new JTextField();
		txt_X5.setBounds(34, 181, 86, 20);
		getContentPane().add(txt_X5);
		txt_X5.setColumns(10);
		
		txt_Y5 = new JTextField();
		txt_Y5.setBounds(145, 181, 86, 20);
		getContentPane().add(txt_Y5);
		txt_Y5.setColumns(10);
		
		JLabel lblXcoordinaat = new JLabel("X-coordinaat");
		lblXcoordinaat.setBounds(34, 32, 86, 14);
		getContentPane().add(lblXcoordinaat);
		
		JLabel lblYcoordinaat = new JLabel("Y-coordinaat");
		lblYcoordinaat.setBounds(145, 32, 86, 14);
		getContentPane().add(lblYcoordinaat);
		
		JLabel label = new JLabel("1");
		label.setBounds(10, 60, 36, 14);
		getContentPane().add(label);
		
		JLabel label_1 = new JLabel("2");
		label_1.setBounds(10, 91, 46, 14);
		getContentPane().add(label_1);
		
		JLabel label_2 = new JLabel("3");
		label_2.setBounds(10, 125, 46, 14);
		getContentPane().add(label_2);
		
		JLabel label_3 = new JLabel("4");
		label_3.setBounds(10, 153, 46, 14);
		getContentPane().add(label_3);
		
		JLabel label_4 = new JLabel("5");
		label_4.setBounds(10, 184, 46, 14);
		getContentPane().add(label_4);
		
		txt_ScenarioName = new JTextField();
		txt_ScenarioName.setBounds(145, 231, 86, 20);
		getContentPane().add(txt_ScenarioName);
		txt_ScenarioName.setColumns(10);
		
		lblNaam = new JLabel("Naam:");
		lblNaam.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNaam.setBounds(74, 234, 46, 14);
		getContentPane().add(lblNaam);
    }
	
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    	
    }
    
}

